package ooday03;

import java.util.Arrays;

//引用类型数组的演示
public class RefArrayDemo {
    public static void main(String[] args) {
//        Dog[] dogs = new Dog[3];//默认值为null，每个元素都是Dog类型，包含3个元素
//        Chick[] chicks = new Chick[3];
//        Fish[] fish = new Fish[2];
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑", 2, "黑色");
        dogs[1] = new Dog("小黄", 1, "黄色");
        dogs[2] = new Dog("小白", 3, "白色");
        System.out.println(dogs[0].name);
        dogs[1].age= 5;
        dogs[2].swim();
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        for (Dog i : dogs) {
            System.out.println(i.name);
            i.eat();
        }

        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("小鸡", 2, "黄色");
        chicks[1] = new Chick("母鸡", 3, "黑色");
        for (Chick j : chicks) {
            System.out.println(j.name);
            j.layEggs();
        }

        Fish[] fish = new Fish[4];
        fish[0] = new Fish("小鱼", 1, "灰色");
        fish[1] = new Fish("大鱼", 3, "金色");
        fish[2] = new Fish("大大鱼", 5, "蓝色");
        fish[3] = new Fish("超大鱼", 7, "金色");
        for (Fish k : fish) {
            System.out.println(k.name);
            k.swim();
        }

    }
}
